// schema扩展相关文档请参阅：https://uniapp.dcloud.net.cn/uniCloud/jql-schema-ext.html
const db = uniCloud.database()
module.exports = {
	trigger: {
		afterCreate: function({
			addDataList
		} = {}) {
			let [{
				article_id,
				comment_id,
				article_type = 0
			}] = addDataList
			if (article_type == 0) { // 对文章点赞
				db.collection('consult').doc(article_id).update({
					like_count: db.command.inc(1)
				})
			} else if (article_type == 1) { // 对圈子点赞
				db.collection('circle').doc(article_id).update({
					like_count: db.command.inc(1)
				})
			}
		},
		afterDelete: function({
			where
		} = {}) {
			let {
				article_id,
				comment_id,
				article_type = 0
			} = where
			if (article_type == 0) { // 对鸡汤取消点赞
				db.collection('consult').doc(article_id).update({
					like_count: db.command.inc(-1)
				})
			} else if (article_type == 1) { // 对圈子取消点赞
				db.collection('circle').doc(article_id).update({
					like_count: db.command.inc(-1)
				})
			}
		}
	}
}